// var n;
// var r = cc.Vec2;
// var c = cc.BlockInputEvents;
// var l = cc.Sprite.Type;
// var d = cc.Sprite.SizeMode;
// var u = cc.Label.Overflow;
// var h = cc.Label.HorizontalAlign;
// var p = cc.Label.VerticalAlign;
// var $buttonAction = require("./AL_Framework_Button_Action");
// var f = cc._decorator;
// var m = f.ccclass;
// var y = f.property;
// var _ = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.button = null;
//         t.node_button_close = null;
//         t.spriteframe_clicked_button = null;
//         t.spriteframe_normal_button = null;
//         t.guide = null;
//         t.spine_chest = null;
//         t.progBar = null;
//         t.dianji_cishu = 0;
//         t.kuaisu_dianji_cishu = 0;
//         t.zuihou_dianji_shijian = 0;
//         t.kuaisu_dianji_jiange = 0;
//         t.completeFastClickTimes = 4;
//         t.handle_button_callback = null;
//         t.xiaohui_huidiao = null;
//         t.isEnd = !1;
//         return t;
//     }
//     var o;
//     __extends(t, e);
//     o = t;
//     t.prototype.onLoad = function () {
//         ailin_sdk_manager.yincangBannerGuanggao();
//     };
//     t.prototype.start = function () {
//         var e = this;
//         this.button.on(
//             cc.Node.EventType.TOUCH_START,
//             function () {
//                 e.button.getComponent(cc.Sprite).spriteFrame = e.spriteframe_clicked_button;
//                 e.guide.active = !1;
//             },
//             this
//         );
//         this.button.on(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this);
//         this.button.on(
//             cc.Node.EventType.TOUCH_CANCEL,
//             function () {
//                 e.button.getComponent(cc.Sprite).spriteFrame = e.spriteframe_normal_button;
//             },
//             this
//         );
//         this.guide
//             .getChildByName("arrow")
//             .runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, new r(0, -20)), cc.moveBy(0.2, new r(0, 20)))));
//         this.node_button_close.on(
//             cc.Node.EventType.TOUCH_END,
//             function () {
//                 e.node.destroy();
//             },
//             this
//         );
//         this.node_button_close.active = !1;
//         this.spine_chest.setAnimation(0, "animation", !0);
//         this.schedule(function () {
//             if (e.dianji_cishu > 0) {
//                 e.dianji_cishu--;
//             }
//         }, o.decayTime / 1e3);
//         this.schedule(function () {
//             if (!e.isEnd) {
//                 var t = e.progBar.width - o.decayWidth;
//                 t = t < 1 ? 1 : t;
//                 e.progBar.width = t;
//             }
//         }, o.decayTime2 / 1e3);
//         this.sceneName = ailin_sdk_manager.instance.sceneName;
//         ailin_sdk_manager.shezhiChangjingMingcheng("AL_Framework_Chest_Dialog");
//     };
//     t.prototype.handle_event_click_button = function () {
//         this.button.getComponent(cc.Sprite).spriteFrame = this.spriteframe_normal_button;
//         this.guide.active = !1;
//         console.log("chestDialog handle_event_click_button: 是否走流程 " + ailin_sdk_manager.instance.dangqian_duihuakuang_shifou_shiyongzhong);
//         if (!ailin_sdk_manager.instance.dangqian_duihuakuang_shifou_shiyongzhong) {
//             this.button.off(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this);
//             return void this.xianshiChestDonghua();
//         }
//         if (0 == this.progBar.parent.active) {
//             this.progBar.width = 0;
//             this.progBar.parent.active = !0;
//         }
//         var e = new Date().getTime();
//         this.dianji_cishu++;
//         this.zuihou_dianji_shijian = e;
//         var t = (this.dianji_cishu / this.completeFastClickTimes) * 435;
//         console.log("  schedule   dianji_cishu: " + this.dianji_cishu, this.completeFastClickTimes, t);
//         t = t > 435 ? 435 : t;
//         this.progBar.width = t;
//         return this.dianji_cishu >= this.completeFastClickTimes
//             ? ((this.isEnd = !0),
//               this.button.off(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this),
//               this.handle_button_callback &&
//                   (cc.sys.platform == cc.sys.OPPO_GAME
//                       ? ailin_sdk_manager.xianshiJiliShipinGuanggao(this.handle_button_callback)
//                       : this.handle_button_callback()),
//               void this.node.destroy())
//             : void 0;
//     };
//     t.prototype.xianshiChestDonghua = function () {
//         var e = this;
//         this.spine_chest.setAnimation(1, "animation2", !1);
//         this.scheduleOnce(function () {
//             e.spine_chest.setAnimation(2, "animation4", !0);
//             ailin_sdk_manager.showToast("获得神秘力量");
//             if (e.handle_button_callback) {
//                 cc.sys.platform == cc.sys.OPPO_GAME
//                     ? ailin_sdk_manager.xianshiJiliShipinGuanggao(e.handle_button_callback)
//                     : e.handle_button_callback();
//             }
//             e.scheduleOnce(function () {
//                 e.node.destroy();
//             }, 0.5);
//         }, 0.5);
//     };
//     t.xianshiChestDuihuakuang = function (e) {
//         o.showcount++;
//         console.log("xianshiChestDuihuakuang this.showcount:", o.showcount);
//         if (cc.sys.platform == cc.sys.OPPO_GAME) {
//             if (e.kuaisu_dianji_cishu.odds && o.showcount % e.kuaisu_dianji_cishu.odds != 0) {
//                 return;
//             }
//             if (e.kuaisu_dianji_cishu.autoCloseTime && e.kuaisu_dianji_cishu.autoCloseTime > 0) {
//                 setTimeout(function () {
//                     t.destroy();
//                 }, 1e3 * e.kuaisu_dianji_cishu.autoCloseTime);
//             }
//             if (e.kuaisu_dianji_cishu.decay && e.kuaisu_dianji_cishu.decay > 0) {
//                 this.decayTime = e.kuaisu_dianji_cishu.decay;
//             }
//             if (e.kuaisu_dianji_cishu.decayWidth && e.kuaisu_dianji_cishu.decayWidth > 0) {
//                 this.decayWidth = e.kuaisu_dianji_cishu.decayWidth;
//             }
//             if (e.kuaisu_dianji_cishu.decayTime && e.kuaisu_dianji_cishu.decayTime > 0) {
//                 this.decayTime2 = e.kuaisu_dianji_cishu.decayTime;
//             }
//             if (e.kuaisu_dianji_cishu.bottonY) {
//                 this.bottonY = e.kuaisu_dianji_cishu.bottonY;
//             }
//         }
//         var t = this.chuangjian_yuzhiti(e);
//         t.x = 360;
//         t.y = 640;
//         t.getComponent(o).chushihua_shuju(e);
//         cc.director.getScene().addChild(t);
//         console.log("xianshiChestDuihuakuang: success");
//     };
//     t.prototype.chushihua_shuju = function (e) {
//         if (e.kuaisu_dianji_cishu.clickCount) {
//             this.completeFastClickTimes = e.kuaisu_dianji_cishu.clickCount;
//         }
//         if (e.xiaohui_huidiao) {
//             this.xiaohui_huidiao = e.xiaohui_huidiao;
//         }
//         if (e.handle_button_callback) {
//             this.handle_button_callback = e.handle_button_callback;
//         }
//         if (e.wx_kuaisu_dianji_jiange) {
//             this.kuaisu_dianji_jiange = e.wx_kuaisu_dianji_jiange;
//         }
//     };
//     t.prototype.onDestroy = function () {
//         ailin_sdk_manager.shezhiChangjingMingcheng(this.sceneName);
//         if (this.xiaohui_huidiao) {
//             this.xiaohui_huidiao();
//         }
//         ailin_sdk_manager.yincangBannerGuanggao();
//     };
//     t.chuangjian_yuzhiti = function (e) {
//         var t = new cc.Node();
//         var i = cc.winSize;
//         t.width = i.width;
//         t.height = i.height;
//         var n = t.addComponent(cc.Widget);
//         n.isAlignTop = !0;
//         n.isAlignRight = !0;
//         n.isAlignBottom = !0;
//         n.isAlignLeft = !0;
//         n.top = 0;
//         n.right = 0;
//         n.bottom = 0;
//         n.left = 0;
//         n.isAlignVerticalCenter = !0;
//         n.isAlignHorizontalCenter = !0;
//         var a = new cc.Node();
//         a.width = 2160;
//         a.height = 3840;
//         o.tianjia_jingling_tu(a, "Flower/img/common/whiteBg", l.SIMPLE, d.CUSTOM);
//         a.color = new cc.Color(0, 0, 0);
//         a.opacity = 180;
//         a.addComponent(c);
//         t.addChild(a);
//         var s = new cc.Node();
//         o.tianjia_jingling_tu(s, "Flower/img/chest/img/05");
//         s.y = 420;
//         t.addChild(s);
//         var r = new cc.Node();
//         var f = r.addComponent(sp.Skeleton);
//         cc.loader.loadRes("Flower/img/chest/anim/baoxiang", sp.SkeletonData, function (e, t) {
//             f.skeletonData = t;
//             f.setAnimation(0, "animation", !0);
//         });
//         f.premultipliedAlpha = !1;
//         f.loop = !0;
//         r.x = -20;
//         r.y = -100;
//         t.addChild(r);
//         console.log("ChestDialog222: ", f.skeletonData);
//         var m = new cc.Node();
//         m.width = 200;
//         m.height = 80;
//         o.tianjia_jingling_tu(m, "Flower/img/chest/img/2", l.SIMPLE, d.CUSTOM);
//         m.anchorY = 0;
//         m.addComponent($buttonAction.default);
//         var y = m.addComponent(cc.Widget);
//         y.isAlignBottom = !0;
//         y.bottom = 0 + this.bottonY;
//         y.target = cc.director.getScene();
//         var _ = -cc.winSize.height / 2;
//         m.y = cc.winSize.height > 2 * cc.winSize.width ? _ - 110 : _ + 50;
//         if (e.kuaisu_dianji_cishu.btnPosX) {
//             m.x = e.kuaisu_dianji_cishu.btnPosX;
//         }
//         t.addChild(m);
//         var v = new cc.Node();
//         var w = new cc.Node();
//         this.tianjia_jingling_tu(w, "Flower/img/chest/img/1");
//         w.name = "arrow";
//         w.y = 155;
//         v.addChild(w);
//         w.scale = 1.3;
//         var S = new cc.Node();
//         this.tianjia_jingling_tu(S, "Flower/img/chest/img/click_here");
//         S.y = 195;
//         S.active = !1;
//         S.rotation = -45;
//         v.addChild(S);
//         m.addChild(v);
//         var C = new cc.Node("jd_bg");
//         this.tianjia_jingling_tu(C, "Flower/img/chest/img/jd_bg");
//         C.x = 0;
//         C.y = r.y - 180;
//         var b = new cc.Node();
//         b.anchorX = 0;
//         b.width = 435;
//         b.addComponent(cc.Sprite).type = cc.Sprite.Type.TILED;
//         b.getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
//         this.tianjia_jingling_tu(b, "Flower/img/chest/img/jd");
//         b.y = 0;
//         b.x = -217.5;
//         C.addChild(b);
//         t.addChild(C);
//         C.active = !1;
//         var A = new cc.Node();
//         var N = A.addComponent(cc.Label);
//         N.string = "X";
//         N.overflow = u.NONE;
//         N.horizontalAlign = h.CENTER;
//         N.verticalAlign = p.CENTER;
//         N.fontSize = 50;
//         N.lineHeight = 50;
//         N.enableBold = !0;
//         A.x = 260;
//         A.y = 495;
//         A.color = new cc.Color(255, 0, 0);
//         t.addChild(A);
//         var I = t.addComponent(o);
//         I.button = m;
//         I.node_button_close = A;
//         I.guide = v;
//         I.spine_chest = f;
//         I.spine_chest.defaultAnimation = "animation";
//         I.spine_chest.loop = !0;
//         I.progBar = b;
//         console.log("AL_Framework_Chest_Dialog: ", I.spine_chest);
//         cc.loader.loadRes("Flower/img/chest/img/3", cc.SpriteFrame, function (e, t) {
//             if (!e) {
//                 I.spriteframe_clicked_button = t;
//             }
//         });
//         cc.loader.loadRes("Flower/img/chest/img/2", cc.SpriteFrame, function (e, t) {
//             if (!e) {
//                 I.spriteframe_normal_button = t;
//             }
//         });
//         console.log("size: ", cc.winSize, cc.view.getFrameSize());
//         var T = cc.winSize.width / 720;
//         var M = cc.winSize.height / 1280;
//         t.scale = T > M ? M : T;
//         return t;
//     };
//     t.tianjia_jingling_tu = function (e, t, o, i) {
//         if (void 0 === o) {
//             o = cc.Sprite.Type.SIMPLE;
//         }
//         if (void 0 === i) {
//             i = cc.Sprite.SizeMode.TRIMMED;
//         }
//         console.log("tianjia_jingling_tu", e, t);
//         var n = e.getComponent(cc.Sprite) ? e.getComponent(cc.Sprite) : e.addComponent(cc.Sprite);
//         n.type = o;
//         n.sizeMode = i;
//         if (t) {
//             cc.loader.loadRes(t, cc.SpriteFrame, function (e, t) {
//                 e ? console.log("tianjia_jingling_tu err: ", JSON.stringify(e)) : (n.spriteFrame = t);
//             });
//         }
//     };
//     t.bottonY = 0;
//     t.decayTime = 200;
//     t.decayTime2 = 50;
//     t.decayWidth = 8.7;
//     t.showcount = 0;
//     __decorate([y(cc.Node)], t.prototype, "button", void 0);
//     __decorate([y(cc.Node)], t.prototype, "node_button_close", void 0);
//     __decorate([y(cc.SpriteFrame)], t.prototype, "spriteframe_clicked_button", void 0);
//     __decorate([y(cc.SpriteFrame)], t.prototype, "spriteframe_normal_button", void 0);
//     __decorate([y(cc.Node)], t.prototype, "guide", void 0);
//     __decorate([y(sp.Skeleton)], t.prototype, "spine_chest", void 0);
//     __decorate([y], t.prototype, "progBar", void 0);
//     return (o = __decorate([m], t));
// })(cc.Component);
// exports.default = _;

// 引入必要模块和组件
const Vec2 = cc.Vec2;
const BlockInputEvents = cc.BlockInputEvents;
const SpriteType = cc.Sprite.Type;
const SpriteSizeMode = cc.Sprite.SizeMode;
const LabelOverflow = cc.Label.Overflow;
const LabelHorizontalAlign = cc.Label.HorizontalAlign;
const LabelVerticalAlign = cc.Label.VerticalAlign;
const AL_Framework_Button_Action = require("./AL_Framework_Button_Action");
const { ccclass, property } = cc._decorator;

/**
 * 这是一个游戏组件类，用于处理按钮事件和动画。
 */
@ccclass
class AL_Framework_Chest_Dialog extends cc.Component {
    // 属性定义
    @property(cc.Node) button = null;
    @property(cc.Node) node_button_close = null;
    @property(cc.SpriteFrame) spriteframe_clicked_button = null;
    @property(cc.SpriteFrame) spriteframe_normal_button = null;
    @property(cc.Node) guide = null;
    @property(sp.Skeleton) spine_chest = null;
    @property progBar = null;

    dianji_cishu = 0;
    kuaisu_dianji_cishu = 0;
    zuihou_dianji_shijian = 0;
    kuaisu_dianji_jiange = 0;
    completeFastClickTimes = 4;
    handle_button_callback = null;
    xiaohui_huidiao = null;
    isEnd = false;

    static bottonY = 0;
    static decayTime = 200;
    static decayTime2 = 50;
    static decayWidth = 8.7;
    static showcount = 0;

    onLoad() {
        ailin_sdk_manager.yincangBannerGuanggao();
    }

    start() {
        this.button.on(
            cc.Node.EventType.TOUCH_START,
            () => {
                this.button.getComponent(cc.Sprite).spriteFrame = this.spriteframe_clicked_button;
                this.guide.active = false;
            },
            this
        );

        this.button.on(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this);

        this.button.on(
            cc.Node.EventType.TOUCH_CANCEL,
            () => {
                this.button.getComponent(cc.Sprite).spriteFrame = this.spriteframe_normal_button;
            },
            this
        );

        this.guide
            .getChildByName("arrow")
            .runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, new Vec2(0, -20)), cc.moveBy(0.2, new Vec2(0, 20)))));

        this.node_button_close.on(
            cc.Node.EventType.TOUCH_END,
            () => {
                this.node.destroy();
            },
            this
        );

        this.node_button_close.active = false;
        this.spine_chest.setAnimation(0, "animation", true);

        this.schedule(() => {
            if (this.dianji_cishu > 0) {
                this.dianji_cishu--;
            }
        }, AL_Framework_Chest_Dialog.decayTime / 1000);

        this.schedule(() => {
            if (!this.isEnd) {
                let newWidth = this.progBar.width - AL_Framework_Chest_Dialog.decayWidth;
                newWidth = newWidth < 1 ? 1 : newWidth;
                this.progBar.width = newWidth;
            }
        }, AL_Framework_Chest_Dialog.decayTime2 / 1000);

        this.sceneName = ailin_sdk_manager.instance.sceneName;
        ailin_sdk_manager.shezhiChangjingMingcheng("AL_Framework_Chest_Dialog");
    }

    handle_event_click_button() {
        this.button.getComponent(cc.Sprite).spriteFrame = this.spriteframe_normal_button;
        this.guide.active = false;

        console.log("chestDialog handle_event_click_button: 是否走流程 " + ailin_sdk_manager.instance.dangqian_duihuakuang_shifou_shiyongzhong);

        if (!ailin_sdk_manager.instance.dangqian_duihuakuang_shifou_shiyongzhong) {
            this.button.off(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this);
            this.xianshiChestDonghua();
            return;
        }

        if (!this.progBar.parent.active) {
            this.progBar.width = 0;
            this.progBar.parent.active = true;
        }

        const currentTime = new Date().getTime();
        this.dianji_cishu++;
        this.zuihou_dianji_shijian = currentTime;

        let progress = (this.dianji_cishu / this.completeFastClickTimes) * 435;
        console.log("schedule dianji_cishu:", this.dianji_cishu, this.completeFastClickTimes, progress);
        progress = progress > 435 ? 435 : progress;
        this.progBar.width = progress;

        if (this.dianji_cishu >= this.completeFastClickTimes) {
            this.isEnd = true;
            this.button.off(cc.Node.EventType.TOUCH_END, this.handle_event_click_button, this);

            if (this.handle_button_callback) {
                if (cc.sys.platform == cc.sys.OPPO_GAME) {
                    ailin_sdk_manager.xianshiJiliShipinGuanggao(this.handle_button_callback);
                } else {
                    this.handle_button_callback();
                }
            }
            this.node.destroy();
        }
    }

    xianshiChestDonghua() {
        this.spine_chest.setAnimation(1, "animation2", false);

        this.scheduleOnce(() => {
            this.spine_chest.setAnimation(2, "animation4", true);
            ailin_sdk_manager.showToast("获得神秘力量");

            if (this.handle_button_callback) {
                if (cc.sys.platform == cc.sys.OPPO_GAME) {
                    ailin_sdk_manager.xianshiJiliShipinGuanggao(this.handle_button_callback);
                } else {
                    this.handle_button_callback();
                }
            }

            this.scheduleOnce(() => {
                this.node.destroy();
            }, 0.5);
        }, 0.5);
    }

    static xianshiChestDuihuakuang(config) {
        AL_Framework_Chest_Dialog.showcount++;
        console.log("xianshiChestDuihuakuang this.showcount:", AL_Framework_Chest_Dialog.showcount);

        if (cc.sys.platform == cc.sys.OPPO_GAME) {
            if (config.kuaisu_dianji_cishu.odds && AL_Framework_Chest_Dialog.showcount % config.kuaisu_dianji_cishu.odds !== 0) {
                return;
            }
            if (config.kuaisu_dianji_cishu.autoCloseTime && config.kuaisu_dianji_cishu.autoCloseTime > 0) {
                setTimeout(() => {
                    AL_Framework_Chest_Dialog.destroy();
                }, 1000 * config.kuaisu_dianji_cishu.autoCloseTime);
            }
            if (config.kuaisu_dianji_cishu.decay && config.kuaisu_dianji_cishu.decay > 0) {
                this.decayTime = config.kuaisu_dianji_cishu.decay;
            }
            if (config.kuaisu_dianji_cishu.decayWidth && config.kuaisu_dianji_cishu.decayWidth > 0) {
                this.decayWidth = config.kuaisu_dianji_cishu.decayWidth;
            }
            if (config.kuaisu_dianji_cishu.decayTime && config.kuaisu_dianji_cishu.decayTime > 0) {
                this.decayTime2 = config.kuaisu_dianji_cishu.decayTime;
            }
            if (config.kuaisu_dianji_cishu.bottonY) {
                this.bottonY = config.kuaisu_dianji_cishu.bottonY;
            }
        }

        const prefab = this.chuangjian_yuzhiti(config);
        prefab.setPosition(360, 640);
        prefab.getComponent(AL_Framework_Chest_Dialog).chushihua_shuju(config);
        cc.director.getScene().addChild(prefab);
        console.log("xianshiChestDuihuakuang: success");
    }

    chushihua_shuju(config) {
        if (config.kuaisu_dianji_cishu.clickCount) {
            this.completeFastClickTimes = config.kuaisu_dianji_cishu.clickCount;
        }
        if (config.xiaohui_huidiao) {
            this.xiaohui_huidiao = config.xiaohui_huidiao;
        }
        if (config.handle_button_callback) {
            this.handle_button_callback = config.handle_button_callback;
        }
        if (config.wx_kuaisu_dianji_jiange) {
            this.kuaisu_dianji_jiange = config.wx_kuaisu_dianji_jiange;
        }
    }

    onDestroy() {
        ailin_sdk_manager.shezhiChangjingMingcheng(this.sceneName);
        if (this.xiaohui_huidiao) {
            this.xiaohui_huidiao();
        }
        ailin_sdk_manager.yincangBannerGuanggao();
    }

    static chuangjian_yuzhiti(config) {
        const node = new cc.Node();
        const winSize = cc.winSize;
        node.setContentSize(winSize);

        const widget = node.addComponent(cc.Widget);
        widget.isAlignTop = true;
        widget.isAlignRight = true;
        widget.isAlignBottom = true;
        widget.isAlignLeft = true;
        widget.top = 0;
        widget.right = 0;
        widget.bottom = 0;
        widget.left = 0;
        widget.isAlignVerticalCenter = true;
        widget.isAlignHorizontalCenter = true;

        const overlayNode = new cc.Node();
        overlayNode.setContentSize(2160, 3840);
        this.tianjia_jingling_tu(overlayNode, "Flower/img/common/whiteBg", SpriteType.SIMPLE, SpriteSizeMode.CUSTOM);
        overlayNode.color = new cc.Color(0, 0, 0);
        overlayNode.opacity = 180;
        overlayNode.addComponent(BlockInputEvents);
        node.addChild(overlayNode);

        const chestNode = new cc.Node();
        this.tianjia_jingling_tu(chestNode, "Flower/img/chest/img/05");
        chestNode.y = 420;
        node.addChild(chestNode);

        const animNode = new cc.Node();
        const skeleton = animNode.addComponent(sp.Skeleton);
        cc.loader.loadRes("Flower/img/chest/anim/baoxiang", sp.SkeletonData, (err, skeletonData) => {
            skeleton.skeletonData = skeletonData;
            skeleton.setAnimation(0, "animation", true);
        });
        skeleton.premultipliedAlpha = false;
        skeleton.loop = true;
        animNode.setPosition(-20, -100);
        node.addChild(animNode);

        const buttonNode = new cc.Node();
        buttonNode.setContentSize(200, 80);
        this.tianjia_jingling_tu(buttonNode, "Flower/img/chest/img/2", SpriteType.SIMPLE, SpriteSizeMode.CUSTOM);
        buttonNode.anchorY = 0;
        buttonNode.addComponent(AL_Framework_Button_Action.default);

        const widgetButton = buttonNode.addComponent(cc.Widget);
        widgetButton.isAlignBottom = true;
        widgetButton.bottom = this.bottonY;
        widgetButton.target = cc.director.getScene();

        const buttonY = -cc.winSize.height / 2;
        buttonNode.y = cc.winSize.height > 2 * cc.winSize.width ? buttonY - 110 : buttonY + 50;

        if (config.kuaisu_dianji_cishu.btnPosX) {
            buttonNode.x = config.kuaisu_dianji_cishu.btnPosX;
        }
        node.addChild(buttonNode);

        const guideNode = new cc.Node();
        const arrowNode = new cc.Node();
        this.tianjia_jingling_tu(arrowNode, "Flower/img/chest/img/1");
        arrowNode.name = "arrow";
        arrowNode.y = 155;
        guideNode.addChild(arrowNode);
        arrowNode.scale = 1.3;

        const clickHereNode = new cc.Node();
        this.tianjia_jingling_tu(clickHereNode, "Flower/img/chest/img/click_here");
        clickHereNode.y = 195;
        clickHereNode.active = false;
        clickHereNode.rotation = -45;
        guideNode.addChild(clickHereNode);

        buttonNode.addChild(guideNode);

        const progressBgNode = new cc.Node("jd_bg");
        this.tianjia_jingling_tu(progressBgNode, "Flower/img/chest/img/jd_bg");
        progressBgNode.setPosition(0, animNode.y - 180);

        const progressNode = new cc.Node();
        progressNode.anchorX = 0;
        progressNode.width = 435;
        const progressSprite = progressNode.addComponent(cc.Sprite);
        progressSprite.type = SpriteType.TILED;
        progressSprite.sizeMode = SpriteSizeMode.CUSTOM;
        this.tianjia_jingling_tu(progressNode, "Flower/img/chest/img/jd");
        progressNode.setPosition(-217.5, 0);
        progressBgNode.addChild(progressNode);

        node.addChild(progressBgNode);
        progressBgNode.active = false;

        const closeButtonNode = new cc.Node();
        const closeButtonLabel = closeButtonNode.addComponent(cc.Label);
        closeButtonLabel.string = "X";
        closeButtonLabel.overflow = LabelOverflow.NONE;
        closeButtonLabel.horizontalAlign = LabelHorizontalAlign.CENTER;
        closeButtonLabel.verticalAlign = LabelVerticalAlign.CENTER;
        closeButtonLabel.fontSize = 50;
        closeButtonLabel.lineHeight = 50;
        closeButtonLabel.enableBold = true;
        closeButtonNode.setPosition(260, 495);
        closeButtonNode.color = new cc.Color(255, 0, 0);
        node.addChild(closeButtonNode);

        const dialogComponent = node.addComponent(AL_Framework_Chest_Dialog);
        dialogComponent.button = buttonNode;
        dialogComponent.node_button_close = closeButtonNode;
        dialogComponent.guide = guideNode;
        dialogComponent.spine_chest = skeleton;
        dialogComponent.spine_chest.defaultAnimation = "animation";
        dialogComponent.spine_chest.loop = true;
        dialogComponent.progBar = progressNode;

        console.log("AL_Framework_Chest_Dialog: ", dialogComponent.spine_chest);

        cc.loader.loadRes("Flower/img/chest/img/3", cc.SpriteFrame, (err, spriteFrame) => {
            if (!err) {
                dialogComponent.spriteframe_clicked_button = spriteFrame;
            }
        });

        cc.loader.loadRes("Flower/img/chest/img/2", cc.SpriteFrame, (err, spriteFrame) => {
            if (!err) {
                dialogComponent.spriteframe_normal_button = spriteFrame;
            }
        });

        console.log("size: ", cc.winSize, cc.view.getFrameSize());

        const scaleX = cc.winSize.width / 720;
        const scaleY = cc.winSize.height / 1280;
        node.scale = scaleX > scaleY ? scaleY : scaleX;

        return node;
    }

    static tianjia_jingling_tu(node, path, type = SpriteType.SIMPLE, sizeMode = SpriteSizeMode.TRIMMED) {
        console.log("tianjia_jingling_tu", node, path);
        const sprite = node.getComponent(cc.Sprite) || node.addComponent(cc.Sprite);
        sprite.type = type;
        sprite.sizeMode = sizeMode;

        if (path) {
            cc.loader.loadRes(path, cc.SpriteFrame, (err, spriteFrame) => {
                if (err) {
                    console.log("tianjia_jingling_tu err: ", JSON.stringify(err));
                } else {
                    sprite.spriteFrame = spriteFrame;
                }
            });
        }
    }
}

exports.default = AL_Framework_Chest_Dialog;
